// Package sys
// @Link  https://github.com/bufanyun/hotgo
// @Copyright  Copyright (c) 2025 HotGo CLI
// @Author  Ms <133814250@qq.com>
// @License  https://github.com/bufanyun/hotgo/blob/master/LICENSE
// @AutoGenerate Version 2.15.11
package sys

import (
	"context"
	"hotgo/api/admin/userorder"
	"hotgo/internal/model/input/sysin"
	"hotgo/internal/service"
)

var (
	UserOrder = cUserOrder{}
)

type cUserOrder struct{}

// List 查看订单中心列表
func (c *cUserOrder) List(ctx context.Context, req *userorder.ListReq) (res *userorder.ListRes, err error) {
	list, totalCount, err := service.SysUserOrder().List(ctx, &req.UserOrderListInp)
	if err != nil {
		return
	}

	if list == nil {
		list = []*sysin.UserOrderListModel{}
	}

	res = new(userorder.ListRes)
	res.List = list
	res.PageRes.Pack(req, totalCount)
	return
}

// Export 导出订单中心列表
func (c *cUserOrder) Export(ctx context.Context, req *userorder.ExportReq) (res *userorder.ExportRes, err error) {
	err = service.SysUserOrder().Export(ctx, &req.UserOrderListInp)
	return
}

// Edit 更新订单中心
func (c *cUserOrder) Edit(ctx context.Context, req *userorder.EditReq) (res *userorder.EditRes, err error) {
	var id int64
	id, err = service.SysUserOrder().Edit(ctx, &req.UserOrderEditInp)
	res = new(userorder.EditRes)
	res.Id = id
	return
}

// View 获取指定订单中心信息
func (c *cUserOrder) View(ctx context.Context, req *userorder.ViewReq) (res *userorder.ViewRes, err error) {
	data, err := service.SysUserOrder().View(ctx, &req.UserOrderViewInp)
	if err != nil {
		return
	}

	res = new(userorder.ViewRes)
	res.UserOrderViewModel = data
	return
}

// Delete 删除订单中心
func (c *cUserOrder) Delete(ctx context.Context, req *userorder.DeleteReq) (res *userorder.DeleteRes, err error) {
	err = service.SysUserOrder().Delete(ctx, &req.UserOrderDeleteInp)
	return
}

// Status 更新订单中心状态
func (c *cUserOrder) Status(ctx context.Context, req *userorder.StatusReq) (res *userorder.StatusRes, err error) {
	err = service.SysUserOrder().Status(ctx, &req.UserOrderStatusInp)
	return
}
